package main

import (
	"fmt"
	"math"
	"sort"
)

func arrayRankTransform(arr []int) []int {
	arrB := make([]int, len(arr))
	copy(arrB, arr)
	sort.Ints(arrB)
	mp := make(map[int]int)
	pre := math.MinInt
	index := 0
	for i := 0; i < len(arr); i++ {
		if arrB[i] != pre {
			index++
		}
		mp[arrB[i]] = index
		pre = arrB[i]
	}
	for index, b := range arr {
		arrB[index] = mp[b]
	}
	return arrB
}

func main() {
	fmt.Println(arrayRankTransform([]int{37, 37, 12, 28, 9, 100, 56, 80, 5, 12}))
	fmt.Println(arrayRankTransform([]int{100, 100, 100}))
	fmt.Println(arrayRankTransform([]int{}))
}
